<?php
/**
 * 用户管理模型
 *
 * @author chenfenghua <843958575@qq.com>
 * version 2.0
 */

namespace app\backend\modules\user\models;

use Yii;
use app\backend\components\BaseModel;
use app\models\base\Project;
use app\models\base\User;
use app\models\base\BankAccount;

class Appuser extends BaseModel
{
    /**
     * 用户办理离职
     * @param  [type] $user_id [string]
     * @return [type]          [string]
     */
	public function userleave($user_id)
    {
        $db = Yii::$app->db;
        $transaction = $db->beginTransaction();
        try {
            $user = User::find()->where(['user_id'=>$user_id])->one();
            $user->disabled = 1;
            $user->finish_time = time();
            $user->save();
            $bankaccount = BankAccount::find()->where(['user_id'=>$user_id])->one();
            if($bankaccount){    
                $bankaccount->disabled = 1;
                $bankaccount->finish_time = time();
                $bankaccount->save();
            }
            $transaction->commit();
            return 200;
        } catch (\Exception $e) {
            $transaction->rollBack();
            throw $e;
        }
    }
}
